{% extends "AcmeTestBundle:Public:base.html.twig" %}

{% block title %}测试{% endblock %}
{% block sidebar %}{% endblock %}
{% block body %}
    <div class="layui-container">
        <table id="demo" lay-filter="test"></table>
    </div>
{% endblock %}
{% block script %}
    {# 操作 #}
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        layui.use('table', function(){
            var table = layui.table;

            //第一个实例
            table.render({
                elem: '#demo'
                ,url: '/student/get' //数据接口
                ,page: true //开启分页
                ,method:'post'
                ,cols: [[ //表头
                    {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
                    ,{field: 'name', title: '姓名', width:80}
                    ,{field: 'sex', title: '性别', width:80, sort: true}
                    ,{field: 'birth', title: '生日'}
                    ,{field: 'edit', title: '操作',width:200,toolbar:"#barDemo"}
                ]]
            });

            //监听事件
            table.on('tool(test)', function(obj){
                switch(obj.event){
                    case 'add':
                        layer.msg('添加');
                        break;
                    case 'delete':
                        layer.msg('删除');
                        break;
                    case 'update':
                        layer.msg('编辑');
                        break;
                };
            });

        });
    </script>
{% endblock %}